<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>学生信息管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            padding: 30px;
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
            font-size: 32px;
        }

        .btn-container {
            margin-bottom: 20px;
            text-align: right;
        }

        .btn {
            display: inline-block;
            padding: 10px 20px;
            background: #667eea;
            color: white;
            text-decoration: none;
            border-radius: 5px;
            transition: background 0.3s;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }

        .btn:hover {
            background: #5568d3;
        }

        .btn-danger {
            background: #e74c3c;
        }

        .btn-danger:hover {
            background: #c0392b;
        }

        .btn-info {
            background: #3498db;
        }

        .btn-info:hover {
            background: #2980b9;
        }

        .btn-warning {
            background: #f39c12;
        }

        .btn-warning:hover {
            background: #e67e22;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        th {
            background: #667eea;
            color: white;
            font-weight: bold;
        }

        tr:hover {
            background: #f5f5f5;
        }

        .action-links a {
            margin-right: 10px;
        }

        .empty-message {
            text-align: center;
            padding: 40px;
            color: #999;
            font-size: 18px;
        }
    </style>
    <script>
        function confirmDelete(id, name) {
            if (confirm('确定要删除学生 "' + name + '" 的信息吗？')) {
                window.location.href = '${pageContext.request.contextPath}/student?action=delete&id=' + id;
            }
        }
    </script>
</head>
<body>
    <div class="container">
        <h1>学生信息管理系统</h1>

        <div class="btn-container">
            <a href="${pageContext.request.contextPath}/student?action=add" class="btn">+ 添加学生</a>
        </div>

        <c:choose>
            <c:when test="${empty students}">
                <div class="empty-message">
                    暂无学生信息，请添加学生。
                </div>
            </c:when>
            <c:otherwise>
                <table>
                    <thead>
                        <tr>
                            <th>身份证号</th>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>详情</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach var="student" items="${students}">
                            <tr>
                                <td>${student.pId}</td>
                                <td>${student.no}</td>
                                <td>${student.name}</td>
                                <td>
                                    <a href="${pageContext.request.contextPath}/student?action=detail&id=${student.id}" class="btn btn-info">查看详情</a>
                                </td>
                                <td class="action-links">
                                    <a href="${pageContext.request.contextPath}/student?action=edit&id=${student.id}" class="btn btn-warning">修改</a>
                                    <a href="javascript:void(0);" onclick="confirmDelete(${student.id}, '${student.name}')" class="btn btn-danger">删除</a>
                                </td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </c:otherwise>
        </c:choose>
    </div>
</body>
</html>

